package conchmusic.conchmusicclient.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by 76706 on 2017/3/22.
 */

public class MyDBHelp extends SQLiteOpenHelper {
    //name数据库文件名字
    public MyDBHelp(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version, null);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql1="create table if not exists artist(\n" +
                "localArtistId integer primary key AUTOINCREMENT,\n" +
                "artistId integer,\n" +
                "artistName varchar(50),\n" +
                "description varchar(500)\n" +
                ")";
        String sql2="create table if not exists artist_song(\n" +
                "localArtistId integer,\n" +
                "localSongId integer,\n" +
                "primary key(localArtistId,localSongId)\n" +
                ")";
        String sql3="create table if not exists song(\n" +
                "localSongId integer primary key AUTOINCREMENT,\n" +
                "songId integer,\n" +
                "title varchar(50),\n" +
                "albumId integer,\n" +
                "albumName varchar(50),\n" +
                "songUrl varchar(100),\n" +
                "localSongUrl varchar(100),\n" +
                "lyricUrl varchar(100),\n" +
                "localLyricUrl varchar(100),\n" +
                "pictureUrl varchar(100),\n" +
                "localPictureUrl varchar(100)\n" +
                ")";
        String sql4="create table if not exists user(\n" +
                "userId integer primary key,\n" +
                "userName varchar(20) unique,\n" +
                "password varchar(50),\n" +
                "email varchar(50),\n" +
                "createdTime varchar(50),\n" +
                "modifiedTime varchar(50),\n" +
                "isLogin integer\n" +
                ")";
        String sql5="create table if not exists songList(\n" +
                "songListId integer primary key,\n" +
                "songListName varchar(50),\n" +
                "userId integer,\n" +
                "description varchar(50),\n" +
                "createdTime varchar(50),\n" +
                "modifiedTime varchar(50)\n" +
                ")";
        String sql6="create table song_songList(\n" +
                "localSongId integer not null,\n" +
                "songListId integer not null,\n" +
                "primary key(localSongId,songListId)\n" +
                ")";
        String sql7="insert into songList(songListId,songListName,userId,description,createdTime,modifiedTime) values(1,'本地歌单',0,'本地歌曲歌单','2017-4-23','2017-4-23')";
        String sql8="insert into songList(songListId,songListName,userId,description,createdTime,modifiedTime) values(2,'下载歌单',0,'下载歌曲歌单','2017-4-23','2017-4-23')";

        db.execSQL(sql1);
        db.execSQL(sql2);
        db.execSQL(sql3);
        db.execSQL(sql4);
        db.execSQL(sql5);
        db.execSQL(sql6);
        db.execSQL(sql7);
        db.execSQL(sql8);
        Log.i("sqldown1","sqldown1");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}
